import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:dgg_flutter_date_picker/dgg_flutter_date_picker.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: "demo",),
      );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DateTime dateTimeStr = DateTime.now(); 
  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding:false,
      appBar: AppBar(
        title: Text(widget.title),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            SystemNavigator.pop();
          },
        ),
      ),
      body: SingleChildScrollView(
        scrollDirection:Axis.vertical,
        padding: EdgeInsets.only(bottom: 20.0),
        child:Center(
          child: Column(
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 20.0),
                child: FlatButton(
                  color: Colors.blue,
                  highlightColor: Colors.blue[700],
                  colorBrightness: Brightness.dark,
                  splashColor: Colors.grey,
                  child: Container(
                    width: 180.0,
                    height: 60.0,
                    child: Center(
                      child: Text("时间选择器",style: TextStyle(fontSize: 20.0),),
                    ),
                  ),
                  onPressed: () {
                    DatePicker.showDatePicker(
                      context,
                      isDark:true,
                      initialDateTime:dateTimeStr,
                      pickerMode:DateTimePickerMode.time,
                      pickerTheme:DatePickerTheme(
                        confirmTextStyle: TextStyle(
                          fontSize: 16.0,
                          color: Color.fromRGBO(16,187,184, 1),
                          fontWeight: FontWeight.bold
                        ),
                        titleHeight:65.0
                      ),
                      onConfirm: (dateTime, List<int> index,) {
                        print(dateTime);
                        dateTimeStr=dateTime;
                      }
                    );
                  },
                ),
              ),
            ],
          ),
        )
      )
    );
  }
}